<?php
namespace Admin\Controller;

class DashboardController extends BaseController {


	public function index() {
        $this->display();
    }

    public function loginout() {
        session('admin',null);
        echo "<script>location.reload();</script>";
    }

    public function get_server_info() {

        $this->verify_request();

        // 获取分页数据
        $page = $_POST['page'];
        $rows = $_POST['rows'];

        $Mysql = D ('Mysql');
        $ServerConfig = M('ServerConfig');
        $count = $ServerConfig->count();
        $res = $ServerConfig->limit(($page-1)*$rows .','.$rows)->select();

        $data = array();
        foreach ($res as $k=>$v) {
            $data[$k]['name'] = $v['name'];
            $data[$k]['value'] = $v['value'];
        }

        $this->ajaxReturn(array('total'=>$count,'rows'=>$data));
    }

    public function refresh_server_info() {

        $Mysql = D('Mysql');
        $ServerConfig = M ('ServerConfig');
        // 清空原数据
        $ServerConfig->where('1')->delete();
        // 重新获取服务器配置
        $serverinfo = array(
            array('name'=>'服务器标识','value'=>$_SERVER["SERVER_SOFTWARE"]),
            array('name'=>'服务器主机名','value'=>$_SERVER['SERVER_NAME']),
            array('name'=>'服务器系统类型及版本号','value'=>php_uname()),
            array('name'=>'服务器语言','value'=>$_SERVER['HTTP_ACCEPT_LANGUAGE']),
            array('name'=>'服务器WEB端口','value'=>$_SERVER['SERVER_PORT']),
            array('name'=>'服务器时间','value'=>date("Y-m-d H:i:s", time())),
            array('name'=>'服务器允许最大上传附件','value'=>ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled"),
            array('name'=>'服务器脚本最大执行时间','value'=>ini_get("max_execution_time")."秒"),
            array('name'=>'服务器PHP版本','value'=>PHP_VERSION),
            array('name'=>'服务器数据库版本','value'=>$Mysql->getMysqlVersion())
        );

        foreach ($serverinfo as $val) {
            $data['name'] = $val['name'];
            $data['value'] = $val['value'];
            $ServerConfig->add($data);
        }

        $this->ajaxReturn(array('success'=>true));
    }
    

}